package com.isdust.jy.mbank.base;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.isdust.jy.mbank.App;
import com.isdust.jy.mbank.R;

/**
 * Created by zor on 2016/10/13.
 */

public abstract class BaseFragment extends Fragment implements View.OnClickListener{
    protected View mRoot;
    protected App app;
    protected Context mContext;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext=getActivity();
        app = (App)getActivity().getApplication();

    }

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        initData();
        if (mRoot != null) {
            ViewGroup parent = (ViewGroup) mRoot.getParent();
            if (parent != null)
                parent.removeView(mRoot);
        } else {
            mRoot = inflater.inflate(getLayoutId(), container, false);
            // Do something
            onBindViewBefore(mRoot);
            // Bind view
            initWidget(mRoot);

        }
        return mRoot;
    }

    protected void initData() {
    }

    protected abstract int getLayoutId();

    protected void onBindViewBefore(View root) {
        // ...
    }

    protected void initWidget(View root) {

    }
}
